Format Strings

The ToText and CStr functions can use format strings to control how the Number, Currency, Date, Time, or DateTime value passed to the x argument will appear when converted to a String. This section describes how to create format strings for the various data types.

Format strings for fractional Numbers and Currency values

The following characters are used to create format strings for fractional Numbers and Currency values:

Character Description Comments/Examples

#

Represents numerical digits or spaces.

When the original number is converted, # characters are ignored unless the number of # characters in the format string extends beyond the number of significant digits in the original value. Then, for every additional # that appears, a space is added to the string.

If your original value is 125.34:

  • the format string "#" produces the string "125" (number of significant digits exceeds the number of # characters)
  • the format string "###.##" produces the string "125.34" (number of significant digits equal to number of # characters)
  • the format string "####.###" produces the string "125.34" (number of significant digits is less than the number of # characters).

0

Represents numerical digits or zeros (0).

When the original number is converted, 0 characters are ignored unless the number of 0 characters in the format string extends beyond the number of significant digits in the original value. Then, for every additional 0 that appears, a zero is added to the string.

If your original value is 125.34:

  • the format string "0" produces the string "125" (number of significant digits exceeds the number of 0 characters)
  • the format string "000.00" produces the string "125.34" (number of significant digits equal to number of 0 characters)
  • the format string "0000.000" produces the string "0125.340" (number of significant digits is less than the number of 0 characters).

# and 0 characters can be combined in format strings. If your original value is 125.34:

  • the format string "####.0000" produces the string "125.3400".
  • A comma (,)
  • A decimal point (.) indicates where a decimal separator should appear. The actual character that appears as a decimal separator in the resulting string can be changed.

comma (,)

Indicates where a thousands separator should appear.

The actual character that appears as a thousands separator in the resulting string can be changed.


decimal point (.)

Indicates where a decimal separator should appear.

The actual character that appears as a decimal separator in the resulting string can be changed.


How format string can affect values

The following table illustrates how format strings can affect different fractional Numbers and Currency values being converted. In this table, the underscore character (_) represents a space in the resulting string:

Original Value Format string Resulting String

16.13

#

16

16.13

0

16

16.13

##

16

16.13

00

16

16.13

###

_16

16.13

000

016

16.13

#.####

16.13_

16.13

0.0000

16.1300

16125.00

###,###.#

_16,125.0

16125.00

000,000.0

016,125.0

16125.00

000000.0

016125.0



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com